<HTML><HEAD><TITLE>select(++StreamList, +Timeout, -ReadyStreams)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Stream I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>select(++StreamList, +Timeout, -ReadyStreams)</H1>
Returns streams from StreamList which are ready for I/O, blocking at most
Timeout seconds.


<DL>
<DT><EM>StreamList</EM></DT>
<DD>A list of atoms or integers.
</DD>
<DT><EM>Timeout</EM></DT>
<DD>A number or an atom.
</DD>
<DT><EM>ReadyStreams</EM></DT>
<DD>A term unifiable with a list of integers and atoms.
</DD>
</DL>
<H2>Description</H2>
   select/3 is modelled after (and partially implemented using) the
   select() Unix system call.  StreamList is a list of streams where
   input or output is expected to occur.  If I/O is available on some
   streams from the StreamList, ReadyStreams is unified with a list of
   those. The same symbolic stream names are used in both lists.

<P>
   If Timeout is a number, it must be non-negative and less than
   100000000. select/3 then waits for at most Timeout seconds for I/O
   on these streams and if none is available, it unifies ReadyStreams
   with nil.  If Timeout is zero, select/3 does not wait but it
   immediately returns the list of streams where I/O is available.  If
   Timeout is the atom block, select/3 waits until I/O is possible on
   one of the streams in StreamList.

<P>
   The streams in StreamList can be sockets, queues, string streams or
   the null stream.  On Unix systems, pipes, files and ttys are also
   allowed.  On Windows, ttys (the console) is also allowed, but only
   when timeout is 0.

<P>
Notes:
<UL>
<LI>
   Sockets are only considered ready when input (rather than output) is
   possible.
</LI><LI>
   The null stream is never ready.
</LI><LI>
   Unlike the select() system call, select/3 does not test any exceptional
   pending conditions on sockets.
</LI>
</UL>

<P>

<H3>Modes and Determinism</H3><UL>
<LI>select(++, +, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>StreamList is not instantiated or it contains uninstantiated    variables.
<DT><EM>(4) instantiation fault </EM>
<DD>Timeout is not instantiated.
<DT><EM>(5) type error </EM>
<DD>StreamList is not a list of integers and atoms.
<DT><EM>(5) type error </EM>
<DD>Timeout instantiated, but not to a number or an atom.
<DT><EM>(5) type error </EM>
<DD>ReadyStreams is instantiated, but not to a list or nil
<DT><EM>(6) out of range </EM>
<DD>Timeout is a negative number or an atom different from block.
<DT><EM>(141) unimplemented functionality </EM>
<DD>Not implemented for this stream class on this system.
<DT><EM>(170) system interface error </EM>
<DD>The system call was interrupted by a signal.
<DT><EM>(192) illegal stream mode </EM>
<DD>A stream in StreamList is not an input stream or a pipe,    or it is a string stream or null.
<DT><EM>(193) illegal stream specification </EM>
<DD>A stream in StreamList is not open or does not exist.
</DL>
<H2>Examples</H2>
<PRE>
     [eclipse 1]: socket(internet, datagram, s), bind(s, _/40000),
		  socket(internet, datagram, r), bind(r, _/40001),
		  select([s, r], block, Streams).

     &lt;blocks until data arrives&gt;



     [eclipse 1]: open(queue(""), update, q).
     yes.
     [eclipse 2]: select([q],0,L).
     L = []
     yes.
     [eclipse 3]: write(q,hello).
     yes.
     [eclipse 4]: select([q],0,L).
     L = [q]
     yes.




</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/iostream/open-3.html">open / 3</A>, <A HREF="../../kernel/iostream/open-4.html">open / 4</A>, <A HREF="../../kernel/iostream/pipe-2.html">pipe / 2</A>, <A HREF="../../kernel/iostream/socket-3.html">socket / 3</A>, <A HREF="../../kernel/iostream/get_stream_info-3.html">get_stream_info / 3</A>
</BODY></HTML>
